


//
//  NRootViewController.m
//  nncloud
//
//  Created by macfai on 2018/9/17.
//  Copyright © 2018年 youedata. All rights reserved.
#import "KonwledgeViewController.h"
#import "UIColor+Hex.h"
#import "ZNavigationViewController.h"
#import "NRootViewController.h"
#import "NHomeViewController.h"
#import "NBusinessServiceViewController.h"
#import "NMineViewController.h"
#import "NGovDeskViewController.h"
#import "NGovHomeViewController.h"
#import "NZhichengPingshenVC.h"
#import "CamelViewController.h"
#import "MsgViewController.h"
#import "AddressBookViewController.h"
#import "WorkFlowViewController.h"
#import "UserCenterViewController.h"
#import "KonwledgeViewController.h"

@interface NRootViewController ()

@property (nonatomic,strong)NHomeViewController *home;
@property (nonatomic,strong)NBusinessServiceViewController *serve;
@property (nonatomic,strong)NMineViewController *mine;
@property (nonatomic,strong)NGovHomeViewController *govHome;
@property (nonatomic,strong)NGovDeskViewController *govDesk;

@property (nonatomic,strong)CamelViewController *camel;
@property (nonatomic,strong)MsgViewController *msg;
@property (nonatomic,strong)AddressBookViewController *addressBook;
@property (nonatomic,strong)WorkFlowViewController *workflow;
@property (nonatomic,strong)UserCenterViewController *userCenter;
@property(nonatomic,strong)KonwledgeViewController *konwledge;


@end

@implementation NRootViewController

-(NHomeViewController *)home{
    if (!_home) {
        _home = [[NHomeViewController alloc] init];
        _home.title = @"首页";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"home"] selectedImage:[UIImage imageNamed:@"home_s"]];
        _home.tabBarItem=s_bar;
    }
    return _home;
}

-(NBusinessServiceViewController *)serve{
    
    if (!_serve) {
        
        _serve = [[NBusinessServiceViewController alloc] init];
        _serve.title=@"服务";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"服务" image:[UIImage imageNamed:@"serve"] selectedImage:[UIImage imageNamed:@"serve_s"]];
        _serve.tabBarItem=s_bar;
    }
    return _serve;
}

-(NMineViewController *)mine{
    if (!_mine) {
        _mine = [[NMineViewController alloc] init];
        _mine.title = @"我的";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"me"] selectedImage:[UIImage imageNamed:@"me_s"]];
        _mine.tabBarItem=s_bar;
    }
    return _mine;
}

-(NGovDeskViewController *)govDesk{
    
    if (!_govDesk) {
    _govDesk = [[NGovDeskViewController alloc] init];
    _govDesk.title=@"驼峰工区";
    UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@"desk"] selectedImage:[UIImage imageNamed:@"desk_s"]];
    _govDesk.tabBarItem=s_bar;
}

    return _govDesk;
}

-(NGovHomeViewController *)govHome{
    if (!_govHome) {
        _govHome = [[NGovHomeViewController alloc] init];
        _govHome.title=@"政府主页";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"政府主页" image:[UIImage imageNamed:@"home"] selectedImage:[UIImage imageNamed:@"home_s"]];
        _govHome.tabBarItem=s_bar;
    }
    return _govHome;
}

-(CamelViewController *)camel{
    if (!_camel) {
        _camel = [[CamelViewController alloc] init];
        _camel.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _camel.tabBarItem=s_bar;
    }
    return _camel;
}

-(MsgViewController *)msg{
    if (!_msg) {
        _msg = [[MsgViewController alloc] init];
        _msg.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _msg.tabBarItem=s_bar;
    }
    return _msg;
}

-(AddressBookViewController *)addressBook{
    if (!_addressBook) {
        _addressBook = [[AddressBookViewController alloc] init];
        _addressBook.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _addressBook.tabBarItem=s_bar;
    }
    return _addressBook;
}


-(WorkFlowViewController *)workflow{
    if (!_workflow) {
        _workflow = [[WorkFlowViewController alloc] init];
        _workflow.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _workflow.tabBarItem=s_bar;
    }
    return _workflow;
}

- (UserCenterViewController *)userCenter{
    if (!_userCenter) {
        _userCenter = [[UserCenterViewController alloc] init];
        _userCenter.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _userCenter.tabBarItem=s_bar;
    }
    return _userCenter;
}


-(KonwledgeViewController *)konwledge{
    if (!_konwledge) {
        _konwledge = [[KonwledgeViewController alloc] init];
        _konwledge.title=@"知识";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"知识" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _konwledge.tabBarItem=s_bar;
    }
    return _konwledge;
}


- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    NSDictionary *userInfo = [[NSUserDefaults standardUserDefaults]objectForKey:kSaveUserInfoKey];
    YYLog(@"****%@",userInfo[@"userInfoType"]);
    
    if (userInfo) {
        
        NUserModel *model = [NUserModel shareInstance];
        [model setValuesForKeysWithDictionary:userInfo];
        YYLog(@"%@,%@",model.userInfoNickname,[NUserModel shareInstance].userInfoId);
        //自动登录
        [NUserModel shareInstance].isLogin = YES;
        ///接口请求是异步的，会有时间差，所以导致首次加载右上角的小红点不显示，因此下面用了个延时配置tabbar
    }

        [self configTabBarVC];
   
    
}


-(void)configTabBarVC{
    
    
    NSArray * titleArray;
    NSArray * unSelectImageArray;
    NSArray * selectImageArray;
    
        ZNavigationViewController * nav0 = [[ZNavigationViewController alloc] initWithRootViewController:self.msg];
        ZNavigationViewController * nav1 = [[ZNavigationViewController alloc] initWithRootViewController:self.addressBook];
        ZNavigationViewController * nav2 = [[ZNavigationViewController alloc] initWithRootViewController:self.workflow];
        ZNavigationViewController * nav3 = [[ZNavigationViewController alloc] initWithRootViewController:self.userCenter];
       ZNavigationViewController * nav4 = [[ZNavigationViewController alloc] initWithRootViewController:self.konwledge];
        self.viewControllers = @[nav0,nav1,nav2,nav4,nav3];
        
        titleArray = @[@"消息",
                       @"通讯录",
                       @"工作流",
                       @"知识",
                       @"我的"];
        
        unSelectImageArray = @[@"home",
                               @"serve",
                               @"desk",
                               @"serve",
                               @"me",
                               ];
        selectImageArray = @[@"home_s",
                             @"serve_s",
                             @"desk_s",
                             @"serve_s",
                             @"me_s",];
    

    for (int i=0; i < unSelectImageArray.count; i++) {
        
        NSString * titel = titleArray[i];
        
        UIImage * normal_image = [UIImage imageNamed:unSelectImageArray[i]];
        normal_image = [normal_image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        UIImage * selected_image = [UIImage imageNamed:selectImageArray[i]];
        //取消系统对于选中 item 的渲染
        selected_image = [selected_image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        //获取每一个 item
        UITabBarItem *item=[self.tabBar.items objectAtIndex:i];
        
        item = [item initWithTitle:titel
                             image:normal_image
                     selectedImage:selected_image];
        
        //item.imageInsets = UIEdgeInsetsMake(5, 5, -5, -5);
        [item setTitlePositionAdjustment:UIOffsetMake(0, -2)];
        
    }
    
    //设置 tabbar 字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:kDarkGrayColor, NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
    //字体颜色变化
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:kSystemtBlue, NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateSelected];
    self.selectedIndex = 2;
    
}


@end
